docs: orthogonal persistence concept page#16
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new Concepts page explaining ICP’s orthogonal persistence model (how canister state persists across calls and upgrades) and contrasts Motoko’s automatic persistence with Rust’s explicit stable-structures approach.
Changes:
- Replaces the placeholder page with an end-to-end explanation of heap vs. stable memory.
- Adds Motoko (
persistent actor,transient var) and Rust (ic-stable-structures,MemoryManager,StableBTreeMap) examples. - Adds guidance on why heap-serialization upgrade patterns are risky, plus trade-off/comparison tables and next-step links.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
|
||
| A separate, dedicated memory region provided by the Internet Computer runtime. Its sole purpose is to survive canister upgrades. | ||
|
|
||
| - **Size limit:** Hundreds of GB (bounded by the subnet storage limit, approximately 500 GB) |
| - **`#[init]` and `#[post_upgrade]`** handlers must be defined. Stable structures auto-restore, so `post_upgrade` only needs to reinitialize transient state (timers, caches) | ||
| - **No `pre_upgrade` serialization needed** -- data is already in stable memory |
|
|
||
| | | Heap memory | Stable memory | | ||
| |---|---|---| | ||
| | **Size limit** | 4 GB (wasm32) / 6 GB (wasm64) | Hundreds of GB | |
Review: Orthogonal PersistenceMust fix
Suggestions
Verified
|
- Fix memory sizes to use GiB consistently (500 GiB, 4 GiB, 6 GiB) - Add subnet shared storage budget note with link to subnet selection - Soften "bricked" to mention skip_pre_upgrade recovery flag - Change #[init]/#[post_upgrade] from "must" to "should" be defined - Remove "historically" from Rust heap wipe description - Make trade-offs table language-aware (Motoko uses heap for all data) - Add shared storage budget bullet to network-overview subnets section
|
Feedback addressed:
|
- Remove Motoko and Rust code examples (belong in data-persistence guide) - Clarify that orthogonal persistence is Motoko-exclusive; Rust uses explicit stable structures (not orthogonal) - Replace implementation details with conceptual descriptions + links to the data-persistence how-to guide - Add "Further reading" section with Medium articles and YouTube short - Update data-persistence stub brief to cover content moved from here - Add subnet shared storage budget to network-overview
|
Feedback addressed (restructure):
|
- Intro now distinguishes Motoko (transparent) vs Rust (explicit) persistence - Comparison table uses precise "500 GiB per canister, subject to subnet storage budget" instead of vague "up to subnet limit" - Align heap memory to "4 GiB (wasm32) / 6 GiB (wasm64)" in canisters.md and cycles-costs.md to match orthogonal-persistence.md and icskills
|
Feedback addressed:
|
Summary
Concept page explaining ICP's orthogonal persistence model, following Diataxis "explanation" principles (what/why, no how-to code):
persistent actor,transient var) — the only ICP language with transparent persistencepre_upgradeheap serialization anti-pattern andskip_pre_upgraderecoveryImplementation code examples are intentionally omitted — they belong in the data-persistence how-to guide (stub brief updated to cover them).
Also adds a "Shared storage budget" bullet to the network-overview subnets section.
Sync recommendation
Informed by
dfinity/portal— persistence sections, and stable-memory icskill